// let xml = `
//       <bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="sample-diagram" targetNamespace="http://bpmn.io/schema/bpmn" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
//       <bpmn2:process id="process{str}">
//         <bpmn2:startEvent id="StartEvent_01ydzqe"/>
//       </bpmn2:process>
//       <bpmndi:BPMNDiagram id="BPMNDiagram_1">
//         <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="process{str}">
//           <bpmndi:BPMNShape id="StartEvent_01ydzqe_di" bpmnElement="StartEvent_01ydzqe">
//             <dc:Bounds x="162" y="212" width="36" height="36" />
//             <bpmndi:BPMNLabel>
//               <dc:Bounds x="169" y="255" width="22" height="14" />
//             </bpmndi:BPMNLabel>
//           </bpmndi:BPMNShape>
//         </bpmndi:BPMNPlane>
//       </bpmndi:BPMNDiagram>
//     </bpmn2:definitions>`;

const xml =
  `<?xml version="1.0" encoding="UTF-8"?>\n` +
  `<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">\n` +
  `  <bpmn:process id="process-{str}" isExecutable="true" />\n` +
  `  <bpmndi:BPMNDiagram id="BPMNDiagram_1">\n` +
  `    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="process-{str}" />\n` +
  `  </bpmndi:BPMNDiagram>\n` +
  `</bpmn:definitions>`;

export const initTemplate = (): string => {
  const str = uuid();
  return xml.replace(/{str}/g, str);
};
const uuid = () => {
  const s: any[] = [];
  const hexDigits = '0123456789abcdef';
  for (let i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = '-';

  const uuid = s.join('');
  return uuid;
};
